var h = $(window).height(),
    w = $(window).width();
$('.row-hoof').css({height: h + 'px'});
$('.Height').css({height: Math.floor((h - 140) / 2) + 'px'});
$('.clueInput').css({flex: '0 0 '+ Math.floor((h - 140) / 2) + 'px'});
$('#clueInput').css({height: Math.floor((h - 140) / 2) - 55 + 'px'});
var clueInputDom = echarts.init(document.getElementById('clueInput'));
$('.hrefOne').attr('href',hrefAdress + 'thread.html');
$('.hrefTwo').attr('href',hrefAdress + 'sameCase.html');
$('.hrefThree').attr('href',hrefAdress + 'sameCase.html');
$('.hrefFour').attr('href',hrefAdress + 'order.html');
$('.hrefFive').attr('href',hrefAdress + 'notice.html');
$('.hrefSix').attr('href',hrefAdress + 'download.html');
if(!window.sessionStorage.getItem('href')) {
    window.open(hrefAdress + 'showIndex', '_blank');
    window.sessionStorage.setItem('href', 'ok');
}
$(window).resize(function(){
    h = $(window).height();
    w = $(window).width();
    $('.row-hoof').css({height: h + 'px'});
    $('.Height').css({height: Math.floor((h - 140) / 2) + 'px'});
    $('.clueInput').css({flex: '0 0 '+ Math.floor((h - 140) / 2) + 'px'});
    $('#clueInput').css({height: Math.floor((h - 140) / 2) - 55 + 'px'});
    $('.jDiaporama').css({width: $('.slider').width(),height: $('.slider').height()});
    $('.diaporama1').css({width: $('.slider').width(),height: $('.slider').height()});
    clueInputDom.resize();
})
$(document).ready(function(){
    // 轮播 通知通告 工具下载
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/newestInfo',
        async: true,
        data:{
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            caseNum: Math.floor(($('.realTimeAlert').height() - 52) / 31),
            photoNum: 5,
            orderNum: Math.floor(($('.others').height() - 52) / 30),
            noticeNum: Math.floor(($('.others').height() - 52) / 31),
            toolNum: Math.floor(($('.others').height() - 52) / 31)
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                //轮播
                $('.diaporama1').html('');
                if(response.content.photo.length > 0){
                    for(var i = 0; i < response.content.photo.length; i++){
                        $('.diaporama1').append('<li><span><img src="'+ response.content.photo[i].WLLJ +'" onerror="nofind(this)" title="'+ response.content.photo[i].SJ +'" alt="" class="sliderImg" /></span></li>');
                    }
                    $('.diaporama1').show();
                    $(".diaporama1").jDiaporama({
                        auto: true,
                        currentimage:false,//计数器
                        infos:true,//标题显示
                        animationSpeed: "slow",
                        delay: 5,
                        onrollover: false//鼠标悬停显示信息
                    });
                }

                //通知通告
                $('.notice').html('');
                if(response.content.notices.length > 0){
                    for(var i = 0; i < response.content.notices.length; i++){
                        $('.notice').append('<li onclick="noticeDetail('+ nulls(response.content.notices[i].XH) +')"><div class="left"><span class="circle"></span>'+ nulls(response.content.notices[i].MS) +'</div><div class="right">'+ nulls(response.content.notices[i].FBSJ) +'</div></li>');
                    }
                }
                //工具下载
                $('.downloadTools').html('');
                if(response.content.tools.length > 0){
                    for(var i = 0; i < response.content.tools.length; i++){
                        $('.downloadTools').append('<li><div class="left"><a href="'+ nulls(response.content.tools[i].URL) +'">'+ (i + 1) +'、'+ nulls(response.content.tools[i].XZM) +'</a></div></li>');
                    }
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
    //每天实时警情
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/case',
        async: true,
        data: {
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            caseNum: Math.floor(($('.realTimeAlert').height() - 52) / 31),
            photoNum: 5,
            orderNum: Math.floor(($('.others').height() - 52) / 30),
            noticeNum: Math.floor(($('.others').height() - 52) / 31),
            toolNum: Math.floor(($('.others').height() - 52) / 31)
        },
        beforeSend: function () {
            Loading();
        },
        success: function (response) {
            closeLoading();
            if (response.responseCode == '1000') {
                $('.realTimeAlarm').html('');
                if(response.content.case.length > 0){
                    for(var i = 0; i < response.content.case.length; i++){
                        $('.realTimeAlarm').append('<li onclick="showDetail(\''+ nulls(response.content.case[i].AJBH) +'\')"><div class="left"><span class="circle"></span>'+ nulls(response.content.case[i].JYAQ) +'</div><div class="right">'+ nulls(response.content.case[i].SJ) +'</div><input type="hidden" value="'+ nulls(response.content.case[i].AJBH) +'"></li>');
                    }
                }
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
    //指令
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/order',
        async: true,
        data: {
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            caseNum: Math.floor(($('.realTimeAlert').height() - 52) / 31),
            photoNum: 5,
            orderNum: Math.floor(($('.others').height() - 52) / 30),
            noticeNum: Math.floor(($('.others').height() - 52) / 31),
            toolNum: Math.floor(($('.others').height() - 52) / 31)
        },
        beforeSend: function () {
            Loading();
        },
        success: function (response) {
            closeLoading();
            if (response.responseCode == '1000') {
                $('.receiveOrder').html('');
                $('.sendOrder').html('');
                if(response.content.order.length > 0){
                    for(var i = 0; i < response.content.order.length; i++){
                        if(response.content.order[i].flag == 1){
                            $('.receiveOrder').append('<li><span>【接收】</span>'+ nulls(response.content.order[i].COMCONTENT) +'</li>');
                        }else{
                            $('.sendOrder').append('<li><span>【发送】</span>'+ nulls(response.content.order[i].COMCONTENT) +'</li>');
                        }
                    }
                }
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
//个人指令录入
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/clueCount',
        async: true,
        data: {
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            caseNum: Math.floor(($('.realTimeAlert').height() - 52) / 31),
            photoNum: 5,
            orderNum: Math.floor(($('.others').height() - 52) / 30),
            noticeNum: Math.floor(($('.others').height() - 52) / 31),
            toolNum: Math.floor(($('.others').height() - 52) / 31)
        },
        beforeSend: function () {
            Loading();
        },
        success: function (response) {
            closeLoading();
            if (response.responseCode == '1000') {

                if(response.content.clueCount.length > 0){
                    var ORGCASE = response.content.clueCount[0].ORGCASE,//分局案件
                        MYCASE = response.content.clueCount[0].MYCASE,//我的案件
                        ORGCLUE = response.content.clueCount[0].ORGCLUE,//分局线索
                        MYCLUE = response.content.clueCount[0].MYCLUE,//我的线索
                        FKTS = response.content.clueCount[0].FKTS,//反馈指令条数
                        FSZLTS = response.content.clueCount[0].FSZLTS,//发送指令条数
                        JSZLTS = response.content.clueCount[0].JSZLTS;//接收指令条数
                    clueInput(MYCASE,MYCLUE,FKTS,FSZLTS,JSZLTS);
                }
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
    //header头部数据填充
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/amount',
        async: true,
        data: {
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            caseNum: Math.floor(($('.realTimeAlert').height() - 52) / 31),
            photoNum: 5,
            orderNum: Math.floor(($('.others').height() - 52) / 30),
            noticeNum: Math.floor(($('.others').height() - 52) / 31),
            toolNum: Math.floor(($('.others').height() - 52) / 31)
        },
        beforeSend: function () {
            Loading();
        },
        success: function (response) {
            closeLoading();
            if (response.responseCode == '1000') {
                if(response.content.amount.length > 0){
                    //同步案件
                    $('#syCaseLi').attr('data-to',nulls(response.content.amount[0].CASE_AMOUNT));
                    $('#syCaseLi').html();
                    //录入案件
                    $('#inCaseLi').attr('data-to',nulls(response.content.amount[0].RECODE_CASE_AMOUNT));
                    $('#inCaseLi').html();
                    //附件案件
                    // $('#fileCaseLi').attr('data-to',nulls(response.content.amount[0].RECODE_CASE_AMOUNT));
                    // $('#fileCaseLi').html();
                    //线索上传
                    // $('#clueCaseLi').attr('data-to',nulls(response.content.amount[0].RECODE_CASE_AMOUNT));
                    // $('#clueCaseLi').html();
                    //附件线索数量
                    // $('#fileClueLi').attr('data-to',nulls(response.content.amount[0].RECODE_CASE_AMOUNT));
                    // $('#fileClueLi').html();

                    $('.number').each(count);
                }
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
    //案件研判结果推送
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/areaCase',
        async: true,
        data:{
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            areaCaseNum: Math.floor(($('.judgeResult').height() - 52) / 65)
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                $('.caseOrder').html('');
                if(response.content.areaCase.length > 0){
                    for(var i = 0; i < response.content.areaCase.length; i++){
                        $('.caseOrder').append('<li onclick="showDetail(\''+ nulls(response.content.areaCase[i].AJBH) +'\')"><div class="left" id="leftTop'+ (i + 1) +'"></div><div class="right"><ul><li><p class="top">简要案情：'+ nulls(response.content.areaCase[i].JYAQ) +'</p><p class="bottom">相似案件：【相似度'+ nulls(response.content.areaCase[i].XSDZ) +'%】'+ nulls(response.content.areaCase[i].XSJYAQ) +'</p></li></ul></div></li>');
                        circle('leftTop'+ (i+  1),nulls(response.content.areaCase[i].XSDZ));
                    }
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
    //个人关注案件研判结果
    $.ajax({
        type: 'get',
        url: baseUrls + 'workPage/attention',
        async: true,
        data:{
            userCode: $('#userCode').val(),
            orgCode: $('#orgCode').val(),
            userid: $('#userId').val(),
            myCaseNum: Math.floor(($('.perpsonJudge').height() - 52) / 65)
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                $('.attention').html('');
                if(response.content.attention.length > 0){
                    for(var i = 0; i < response.content.attention.length; i++){
                        $('.attention').append('<li onclick="showDetail(\''+ nulls(response.content.attention[i].AJBH) +'\')"><div class="left" id="leftBottom'+ (i + 1) +'"></div><div class="right"><ul><li><p class="top">简要案情：'+ nulls(response.content.attention[i].JYAQ) +'</p><p class="bottom">相似案件：【相似度'+ nulls(response.content.attention[i].XSDZ) +'%】'+ nulls(response.content.attention[i].XSJYAQ) +'</p></li></ul></div></li>');
                        circle('leftBottom'+ (i+  1),nulls(response.content.attention[i].XSDZ));
                    }
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
    //个人待办事宜
    $.ajax({
        type: 'get',
        url: baseUrls + 'alertMsg',
        async: true,
        data:{
            orgId: $('#orgId').val(),
            userCode: $('#userCode').val(),
            userId: $('#userId').val(),
            roleEnName: $('#roleEnName').val()
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                var datas = '',//数据填充
                    num = 0;//个数
                //待我审核指令
                // <img src="index/img/write.gif" class="gifImg">
                if(response.content.command && response.content.command != 0){
                    datas += '<li><span class="wordBox">【审核】</span><a href="clueExamine.html?type=1"><span class="textBox">待我审核指令&nbsp&nbsp<b class="alertB">'+ nulls(response.content.command) +'</b></span></a></li>';
                    num ++;
                }
                //待我审核线索
                // <img src="index/img/write.gif" class="gifImg">
                if(response.content.myClue && response.content.myClue != 0){
                    datas += '<li><span class="wordBox">【审核】</span><a href="clueExamine.html?type=0"><span class="textBox">待我审核线索&nbsp&nbsp<b class="alertB">'+ nulls(response.content.myClue) +'</b></span></a></li>';
                    num ++;
                }
                //我未审核指令
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.myCommand != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="myExamine.html?type=1"><span class="textBox">我未审核指令&nbsp&nbsp<b class="alertB">'+ nulls(response.content.myCommand) +'</b></span></a></li>';
                    num ++;
                }
                //我未审核线索
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.myClue != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="myExamine.html?type=0"><span class="textBox">我未被审核线索&nbsp&nbsp<b class="alertB">'+ nulls(response.content.myClue) +'</b></span></a></li>';
                    num ++;
                }
                //我未回复的指令
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.noReplyCom != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="order.html"><span class="textBox">我未回复的指令&nbsp&nbsp<b class="alertB">'+ nulls(response.content.noReplyCom) +'</b></span></a></li>';
                    num ++;
                }
                //我的指令(未通过)
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.myFailCom != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="myExamine.html?type=1"><span class="textBox">我的指令(未通过)&nbsp&nbsp<b class="alertB">'+ nulls(response.content.myFailCom) +'</b></span></a></li>';
                    num ++;
                }
                //我的指令(通过)
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.mySucCom != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="myExamine.html?type=1"><span class="textBox">我的指令(通过)&nbsp&nbsp<b class="alertB">'+ nulls(response.content.mySucCom) +'</b></span></a></li>';
                    num ++;
                }
                //我的线索 (未通过)
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.myFailClue != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="myExamine.html?type=0"><span class="textBox">我的线索(未通过)&nbsp&nbsp<b class="alertB">'+ nulls(response.content.myFailClue) +'</b></span></a></li>';
                    num ++;
                }
                //我的线索 (通过)
                // <img src="index/img/eye.gif" class="gifImg">
                if(response.content.mySucClue  != 0){
                    datas += '<li><span class="wordBox">【查看】</span><a href="myExamine.html?type=0"><span class="textBox">我的线索(通过)&nbsp&nbsp<b class="alertB">'+ nulls(response.content.mySucClue) +'</b></span></a></li>';
                    num ++;
                }
                if(num > 0){
                    alertBox(datas,num);
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
})
//圆环所有
function circle(id,num){
    var myChart = echarts.init(document.getElementById(id));
    if(num == '无'){
        num = 0;
    } else if(num > 100){
        num = 100;
    }
    var labelTop = {
        normal : {
            label : {
                show : true,
                position : 'center',
                formatter : '{b}',
                textStyle: {
                    baseline : 'top'
                }
            },
            labelLine : {
                show : false
            }
        }
    };
    var labelFromatter = {
        normal : {
            label : {
                formatter : function (params){
                    return 100 - params.value + '%'
                },
                textStyle: {
                    baseline : 'bottom',
                    color: '#7fd7ff'
                }
            }
        },
    }
    var labelBottom = {
        normal : {
            color: '#fff',
            label : {
                show : true,
                position : 'center'
            },
            labelLine : {
                show : false
            }
        },
        emphasis: {
            color: 'rgba(0,0,0,1)'
        }
    };
    var radius = [20, 25];
    var option = {
        backgroundColor: 'rgba(0,0,0)',
        series : [
            {
                type : 'pie',
                center : ['50%', '50%'],
                radius : radius,
                y: '50%',   // for funnel
                x:'50%', // for funnel
                itemStyle : labelFromatter,
                data : [
                    {name:'other',value: 100 - num, itemStyle: labelBottom},
                    {name:'相似度',value: num,itemStyle: labelTop}
                ]
            }
        ]
    };
    myChart.setOption(option);
}
//录入
function clueInput(MYCASE,MYCLUE,FKTS,FSZLTS,JSZLTS){
    var option = {
        calculable : false,
        tooltip: {
            show: true
        },
        lineStyle: {
            color: 'transparent'
        },
        grid : {
            x: 20,
            y: 10,
            x2: 0,
            y2: 30,
            borderWidth: 0
        },
        xAxis : [
            {
                type : 'category',
                data : ['我的案件','我的线索','反馈指令','发送指令','接收指令'],
                splitLine: {
                    show: false
                },
                splitArea: {
                    show: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                axisLine: {
                  show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                splitLine: {
                    show: false
                },
                splitArea: {
                    show: false
                }
            }
        ],
        series : [
            {
                name:'数量',
                type:'bar',
                data:[MYCASE,MYCLUE,FKTS,FSZLTS,JSZLTS],
                itemStyle: {
                    normal: {
                        label: {
                            show: true
                        },
                        color: function (params) {
                            var colorList = [ '#ff7f50', '#87cefa', '#da70d6', '#32cd32', '#6495ed'];
                            return colorList[params.dataIndex];
                        }
                    },
                    emphasis: {
                        color: function (params) {
                            var colorList = [ '#6b8e23', '#ff00ff', '#3cb371', '#b8860b', '#30e0e0' ];
                            return colorList[params.dataIndex];
                        }
                    }
                },
                barWidth: 10
            }
        ]
    };
    clueInputDom.setOption(option);
}
//案件详情
function showDetail(uniq){
    layer.open({
        type: 2,
        area: ['90%', h * 0.9 + 'px'],
        fixed: false, //不固定
        maxmin: false,
        content: 'layer/layer.html?' + uniq + '&' + $('#userId').val()
    });

}
//通知通告详情
function noticeDetail(xh){
    window.open('noticeDetail.html?xh=' + xh,'_blank');
}
function alertBox(datas,num){
    layer.open({
        title: '个人工作簿',
        type: 1,
        anim: 6,
        shade: 0,//遮罩层
        // skin: 'layui-layer-rim', //加上边框
        offset: 'auto',
        closeBtn: 0,
        maxmin: true,
        area: ['420px', 34 * num + 42 + 'px'], //宽高
        content: '<ul class="myDatas">'+ datas +'</ul>',
        success: function(layero, index){
            setTimeout(function(){
                $(layero).animate({
                    left: w - 420,
                    top: h - (34 * num + 42)
                },1000)
            },1000)
        },
        min: function(layero){
            layero.css('left', w - 180);
        },
        restore: function(layero){
            layero.css({left: w - 410, top: h - (34 * num + 42)});
        }
    });
}